$(function () {
    var
        _user,											//用户信息
        _query = {"index": 0, "size": CONFIG_MANAGER.pageSize},	//请求条件·
        _html = [],										//html字符串
        _myscroll,										//滚动
        _thispage,										//当前页
        _pullUp,
        _pullDown;

    var showPage = function () {
        this.init();
    };
    showPage.prototype = {
        init: function () {
            this.loadData();
            this.addScroll();
            this.bindEvent();
        },
        addScroll: function () {
            _pullUp = $("#pullUp");
            _pullDown = $("#pullDown");
            _myscroll = new IScroll('#wrapper', {
                probeType: 2,
                scrollbars: true,
                mouseWheel: false,
                fadeScrollbars: true,
                bounce: true,
                interactiveScrollbars: false,
                shrinkScrollbars: 'scale',
                click: true,
                keyBindings: true,
                momentum: true
            });
            _myscroll.on("scrollEnd", function () {
                console.log("this.y=" + this.y);
                console.log("this.maxScrollY=" + this.maxScrollY);
                //console.log(this);
                //console.dir(this.maxScrollY);
                if ((this.y < 0) && (this.y == this.maxScrollY)) {
                    console.log("滚动到底部");
                    _pullUp.show();
                    setTimeout(function () {
                        _query.index++;
                        _thispage.loadShowList();
                    }, 500);
                } else if ((this.y == 0) && (this.y != this.maxScrollY)) {
                    console.log("滚动到顶部");
                    _pullDown.show();
                    setTimeout(function () {
                        _query.index--;
                        if (_query.index < 0) {
                            _query.index = 0;
                        }
                        ;
                        _thispage.loadShowList();
                    }, 500);
                }
            });
        },
        //加载
        loadData: function () {
            _user = getLocalStorage(STORAGE_MANAGER.user);
            if (!_user) {
                redirect("../account/login.html");
                return false;
            } else {
                //alert( user.id );
            }
            ;
            this.loadShowList();
        },
        loadShowList: function () {
            var requestUrl = CONFIG_MANAGER.RequstUrl + "v1/fans/my/" + _query.index + "-" + _query.size;
            $.ajax({
                type: "GET",
                url: requestUrl,
                async: true,
                headers: {"token": _user.token},
                beforeSend: function () {
                    $.showWaiting("等待中");
                }
            }).done(function (data) {
                setTimeout(function () {
                    $.closeWaiting();
                }, 500);
                _thispage.loadList(JSON.parse(data));
            });
        },
        //加载列表
        loadList: function (data) {
            var length = data.data.length, list = data.data.concat(data.data), _html = [];
            ;
            if (0 == length) {
                $("#showList").html('<div class="zhanwushuju"><img src="../../images/zanwushuju.png"><br>暂无数据</div>');
            } else {
                $.each(list, function (i, show) {
                    _html.push('<div class="mbtopbottom sqshbg">');
                    _html.push('<div class="with100 overflow">');
                    _html.push('<div class="ddnybbt mbbottom">');
                    _html.push('<p class="dfktbdw">');
                    var src = "";
                    switch (show.audit_status) {
                        case 0:
                            src = "../../images/yfbtb2.png";
                            break;
                        case 1:
                            src = "../../images/yfbtb1.png";
                            break;
                        case 2:
                            src = "../../images/yfbtb3.png";
                            break;
                        default:
                            break;
                    }
                    _html.push('<img src="' + src + '" />');
                    _html.push('</p>');
                    _html.push('<p class="dddpt">');
                    if (2 == show.audit_status) {
                        _html.push('<span class="ljfx ljfxzi">立即分享</span>');
                    }
                    _html.push('</p>');
                    _html.push('</div>');
                    _html.push('<dl class="cpxqxztop cpxqxztop1 mtop0">');
                    _html.push('<dt><img src="../../images/zxtu2.jpg" /></dt>');
                    _html.push('<dd>');
                    _html.push('玫瑰花嫩白精油手工皂夏季专 嫩白祛除黄玫瑰花嫩白精油手工皂夏季专 ..');
                    _html.push('</dd>');
                    _html.push('<dd class="wlxxlc wlxxlc5 huisezi"><span class="huisezi  floatr">' + toDateString(show.create_time, 'yyyy-mm-dd hh:MM:ss') + '</b></span> 来源：小苹果</dd>');
                    _html.push('</dl>');
                    _html.push('</div>');
                    _html.push('</div>');
                });
                $("#showList").html(_html.join(''));
            }
            setTimeout(function () {
                _myscroll.refresh();
                _pullUp.hide();
                _pullDown.hide();
            }, 100);
        },
        //页面事件
        bindEvent: function () {
            //点击返回
            $("#back").on("tap", function () {
                back()
            });

        },


    };
    _thispage = new showPage();
});